import 'package:flutter/material.dart';

/// 店铺数据
class AppStoreModel extends ChangeNotifier {
  // 绑定店铺
  int _bindingStoreId;

  // 当前店铺
  int _currentStoreId;

  // 可切换店铺
  Map<String, String> _storeList;

  // 可管理店铺
  Map<String, String> _manageableStoreList;

  AppStoreModel() {
    debugPrint('$this init');
  }

  int get bindingStoreId => _bindingStoreId ?? 1;

  set bindingStoreId(int value) {
    debugPrint('$this set bindingStoreId = $value');
    if (_bindingStoreId != value) {
      _bindingStoreId = value;
      notifyListeners();
    }
  }

  int get currentStoreId => _currentStoreId ?? bindingStoreId;

  set currentStoreId(int value) {
    debugPrint('$this set currentStoreId = $value');
    if (_currentStoreId != value) {
      _currentStoreId = value;
      notifyListeners();
    }
  }

  Map<String, String> get storeList => _storeList ?? {};

  Map<String, String> get manageableStoreList => _manageableStoreList ?? {};

  void updateStoreList(Map<String, String> storeList, List<int> unManaged) {
    _storeList = storeList;
    var manageableStoreList = <String, String>{}..addAll(storeList);
    unManaged.forEach((value) {
      manageableStoreList.remove(value.toString());
    });
    _manageableStoreList = manageableStoreList;
  }

  @override
  void dispose() {
    debugPrint('$this dispose');
    super.dispose();
  }
}

/// 登录数据
class AppLoginModel extends ChangeNotifier {
  // 默认认为是登录状态，让接口访问来触发失效。
  bool _isLogin = true;

  AppLoginModel() {
    debugPrint('$this init');
  }

  bool get isLogin => _isLogin;

  set isLogin(bool value) {
    debugPrint('$this $value');
    _isLogin = value;
    notifyListeners();
  }

  @override
  void dispose() {
    debugPrint('$this dispose');
    super.dispose();
  }
}
